﻿/**
 * 
 * Copyright 2009 Mike Jamer [email: mikejamer@gmail.com ]
 * 
 * This File is part of Moose IRC
 * 
 * MooseIRC is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * MooseIRC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with MooseIRC.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace moose.irc.standard
{
    /// <summary>
    /// Core Private Message Processing Module
    /// </summary>
    /// <remarks>
    /// This is going to require an update to the message parsing, 
    /// we need sender, command, addressee, Parameters, 
    /// and in a much better format than just a string array.
    /// 
    /// Without this, we cannot properly handle messages, in either direction.
    /// </remarks>
    [CLSCompliant(true)]
    [Response(
        name = "Private Message Response",
        description = "Provides Core Logic for handling private messages.  This means user to user, channel messages, CTCP or whatever",
        author = "Mike MacKenzie-Jamer <email: mikejamer@gmail.com>",
        version = "0.1")]
    [Trigger(TriggerText = "privmsg")]
    [Trigger(TriggerText = "PRIVMSG")]
    public sealed class PrivMsgResponse : IrcAction
    {

        protected override IrcState valid_states()
        {
            return IrcState.Registered;
        }

        protected override void action(IrcClient client, IrcMessage input)
        {

            string source = input.Source;
            string dest = input.Arguments[0];
            string message = input.Arguments[1];

            if (dest[0] == '#' || dest[0] == '@') {
                IrcChannel chan = client.getChannel(dest);
                source = source.Substring(0, source.IndexOf('!'));
                chan.echo("<" + source + "> " + message);
            }

            return;
        }
    }
}
